<html lang="en">

<head>
    <!-- 官网jquery压缩版引用地址: -->
    <script src="http://code.jquery.com/jquery-2.1.4.min.js"></script>
    <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
    <script src="https://code.jquery.com/jquery-3.0.0.min.js"></script>
    <!-- 百度压缩版引用地址: -->
    <script src="http://libs.baidu.com/jquery/2.1.4/jquery.min.js"></script>
    <!-- 微软压缩版引用地址: -->
    <script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-2.1.4.min.js"></script>


    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Comment</title>
    <link rel="stylesheet" href="../css/comment.css">
    <link rel="stylesheet" href="../css/pingji_register.css">
</head>

<body>
    <div class="nav">
        <div class="head">
            <div class="head-img">
                <img src="../image/head1.jpeg" alt="ggggg" class="img">
            </div>

        </div>
        <div class="funcBar">
            <div class="choice">

            </div>
        </div>
    </div>
    <div class="login-container">
        <div class="login-card">
            <div id="login-card-title">
                <b>注册</b><br>
                <b>是否成为评鉴师</b><input type="checkbox" id="check" width="13px" height="13px">
            </div>
            <div id="login-card-container">
                <div id="login-card-container-login">
                    <div id="login-card-container-login-card">
                        <div id="id-login-mess">
                            <div class="login-mess">
                                <div><b>用户名</b></div>
                            </div>
                            <div class="login-mess">
                                <div><b>密码</b></div>
                            </div>
                            <div class="login-mess">
                                <div><b>确认密码</b></div>
                            </div>
                        </div>
                        <div id="input-user-password">
                            <div class="login-input">
                                <input type="text" name="username" id="input-username" >
                            </div>
                            <div class="login-input">
                                <input type="password" name="password" id="input-password">
                            </div>
                            <div class="login-input">
                                <input type="password" name="password" id="input-password2">
                            </div>
                        </div>
                    </div>
                    <button id="button-submit" type="button">注册</button>
                </div>

            </div>
        </div>
    </div>


    <script>
        let hostPath = 'http://localhost:8081/';
        let btn = document.querySelector("#button-submit");
        btn.addEventListener('click', function () {
            console.log("点击注册");
            let input1 = document.querySelector("#input-username");
            let input2 = document.querySelector("#input-password");
            let input3 = document.querySelector("#input-password2");
            console.log(input1.value);
            if (input1.value == "" || input2.value == "" || input3.value == "") {
                alert("必填选项未填");
            }
            if (checkPassword(input2.value, input3.value)) {
                let obj={"username":input1.value,"password":input2.value,"isVIP":$("#check").is(":checked")};
                console.log($("#check").is(":checked"));
                // 发送请求
                $.ajax({
                    type :'POST',
                    url: hostPath + 'register',  
                    data: JSON.stringify(obj),
                    contentType:"application/json",
                    headers:{
                        'Access-Control-Allow-Origin':'*'
                    },
                    success: function (data) {
                        console.log("返回成功");
                        alert(data.message);
                        document.location.href="../index.html";
                    },
                    error: function (data) {
                        alert(data.message);
                        console.log("error");
                    }
                })
            }
            else {
                alert("两次输入的密码不同");
            }
        });
        function checkPassword(password1, password2) {
            if (password1 == password2) {
                return true;
            }
            else {
                return false;
            }
        }
    </script>
</body>

</html>